package com.telecom.cms.dbconnect;

import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

/**
 * @author yueyingnishang
 * 
 */
public class DataSourceFactory {

	private static DataSource ds;

	/**
	 * @return
	 * @throws SQLException
	 */
	public static DataSource getDataSource() throws SQLException {

		if (ds == null) {
			try {
				Context initCtx = new InitialContext();
				Context ctx = (Context) initCtx.lookup("java:comp/env");
				Object obj = (Object) ctx.lookup("jdbc/TeradataCMS");
				ds = (DataSource) obj;
			} catch (NamingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
		return ds;
	}

}
